// functionPage/pages/minePage/mySubmitInfo/myExperienceInfo/myExperienceInfo.js
import throttle from '../../../../../utils/throttle.js';
import Http from '../../../../../utils/http.js';
const http = new Http();
const app = getApp();
// 类型 01录入了FT测试点 02录入了NFC测试测试点 03录入了FT测试路线 04录入了NFC测试路线 05打卡 06发布了xx城市公告  07发布了项目通告 08发起了互动问答 09回复了互动问答 10录入了当地经验 11发布了租车推荐 12发起了住宿推荐 13发布了出行建议 14发起了美食推荐 15发起了营业厅信息 16录入基站参数 17新建运营商18新建套餐19申请删除
Page({
    /**
     * 页面的初始数据
     */
    data: {
        newsArr: [],
        pageNum: 0,
        loading: true,
        loadingAll: false,
        typeValue: [
            {
                name: 'FT测试点',
                type: '01',
                path: '/pages/homePageInfo/ftInfo/ftInfo?review=02&',
            },
            {
                name: 'NFC测试点',
                type: '02',
                path: '/pages/homePageInfo/nfcInfo/nfcInfo?review=02&',
            },
            {
                name: 'FT测试路线',
                type: '03',
                path: '/pages/homePageInfo/ftRouteInfo/ftRouteInfo?review=02&',
            },
            {
                name: 'NFC测试路线',
                type: '04',
                path:
                    '/pages/homePageInfo/nfcRouteInfo/nfcRouteInfo?review=02&',
            },
            {
                name: '城市公告',
                type: '06',
                path:
                    '/functionPage/pages/secretary/noticeInfo/noticeInfo?review=02&',
            },
            {
                name: '互动问答',
                type: '08',
                path:
                    '/pages/notice/projectTeam/interactiveQuestionAndAnswer/interactiveQuestionAndAnswer?',
            },
            {
                name: '租车推荐',
                type: '11',
                path: '/functionPage/pages/cszxDetail/cszxDetail?type=01&',
            },
            {
                name: '住宿推荐',
                type: '12',
                path: '/functionPage/pages/cszxDetail/cszxDetail?type=03&',
            },
            {
                name: '出行建议',
                type: '13',
                path: '/functionPage/pages/cszxDetail/cszxDetail?type=04&',
            },
            {
                name: '美食推荐',
                type: '14',
                path: '/functionPage/pages/cszxDetail/cszxDetail?type=02&',
            },
            {
                name: '营业厅信息',
                type: '15',
                path:
                    '/pages/homePageInfo/business-hall/business-hall?review=02&',
            },
            {
                name: '基站参数',
                type: '16',
                path: '/functionPage/pages/review/networkType/networkType?',
            },
            {
                name: '运营商',
                type: '17',
                path:
                    '/functionPage/pages/review/operatorDetail/operatorDetail?review=02&',
            },
            {
                name: '套餐建议',
                type: '18',
                path: '/functionPage/pages/review/packageDetail/packageDetail?',
            },
        ],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getNewsList();
    },

    // 获取消息列表
    getNewsList() {
        if (!this.data.loadingAll) {
            this.setData({
                pageNum: this.data.pageNum + 1,
                loading: true,
                loadingAll: false,
            });
            let data = {
                authId: app.globalData.authId,
                origintype: '03',
                pageNo: this.data.pageNum,
                pageSize: 20,
            };
            http.getRequest('cjMap/getRelatedMsgList', data).then((res) => {
                if (res.status == 0) {
                    res.data.forEach((item) => {
                        if (item.pctype != '20') {
                            item.createtime = app.timeago(item.createtime);
                            // 00点赞、01评论、02回复、03提问、04回答提问、05设为优秀、06置顶、07精华、08审核通过、09审核拒绝/删除、10审核推优
                            // 处理审核消息标题
                            let typeName; //类型名称
                            for (
                                let j = 0;
                                j < this.data.typeValue.length;
                                j++
                            ) {
                                if (
                                    this.data.typeValue[j].type == item.pctype
                                ) {
                                    typeName = this.data.typeValue[j].name;
                                    item.path =
                                        this.data.typeValue[j].path +
                                        'id=' +
                                        item.eventid +
                                        '&infoId=' +
                                        item.ftspelocationid +
                                        '&operatorid=' +
                                        item.cityoperatorid;
                                }
                            }
                            const action =
                                app.globalData.uid === item.originuid
                                    ? '发布'
                                    : '编辑';
                            if (item.type === '08') {
                                item.review_title = `您${action}的${typeName}被审核通过`;
                            }
                            if (item.type === '09') {
                                item.review_title = `您${action}的${typeName}因不符合要求被删除`;
                            }
                            if (item.type === '10') {
                                item.review_title = `恭喜，您${action}的${typeName}被设置为优秀`;
                            }
                            if (item.pctype == '08') {
                                item.detail = '互动问答';
                            } else if (item.pctype == '16') {
                                item.detail = '基站参数';
                            } else if (item.pctype == '18') {
                                item.detail = '套餐建议';
                            } else {
                                item.detail =
                                    item.country === '中国'
                                        ? `${item.city}`
                                        : `${item.country} ${item.city || ''}`;
                            }
                            this.data.newsArr.push(item);
                        }
                    });
                    this.setData({
                        newsArr: this.data.newsArr,
                        loading: false,
                    });

                    if (res.pager.currentPage >= res.pager.totalPages) {
                        this.setData({
                            loadingAll: true,
                        });
                    }
                } else {
                    this.setData({
                        loadingAll: true,
                        loading: false,
                    });
                }
            });
        }
    },

    changeNav: throttle(
        function (e) {
            let { nav, id } = e.currentTarget.dataset;
            console.log(nav);
            wx.navigateTo({
                url: `${nav}`,
            });
            const index = this.data.newsArr.findIndex((item) => {
                return item.id === id;
            });
            this.setData({
                [`newsArr[${index}].readflg`]: '01',
            });
        },
        200,
        {
            trailing: false,
        }
    ),
});
